{extend name="base" /}
{block name="content"}
<script language="javascript" type="text/javascript" src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
	<div class="m-main-title">
		<div class="m-container-fluid">
			<a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
			<span class="icon-angle-right"></span>
			<span>商城</span>
			<span class="icon-angle-right"></span>
			<span>商品管理</span>
			<span class="icon-angle-right"></span>
			<span>商品管理</span>
			<span class="icon-angle-right"></span>
			<span>{$info ? '编辑' : '添加'}商品</span>
			<a class="u-flush"><i class="icon-repeat"></i></a>
		</div>
	</div>
	<div class="m-main-content">
		<div class="m-container">
			<div class="m-form">
				<form class="layui-form" id="j_form">
					<table class="m-table">
						<tbody>
						<tr>
							<th colspan="2">商品信息</th>
						</tr>
						<tr>
							<td width="15%"><label for="goods_name">商品名称<em>*</em></label></td>
							<td><input type="text" class="u-ipt u-ipt-longer" name="goods_name" id="goods_name" placeholder="请输入商品名称" value="{$info.goods_name}" /></td>
						</tr>
						<tr  style="display: none">
							<td width="15%"><label for="goods_sn">商品货号</label></td>
							<td><input type="text" class="u-ipt u-ipt-long" name="goods_sn" id="goods_sn" placeholder="请输入商品货号" value="{$info.goods_sn}" /></td>
						</tr>
						<tr>
							<td><label for="">所属分类<em>*</em></label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="category_id" lay-filter="category_id">
										<option value="0">请选择分类</option>
										{foreach name="categories" item="v"}
										<option value="{$v.id}"{if condition="!$v['is_last']"} disabled{/if}{if condition="$info['category_id'] eq $v['id']"} selected{/if}>{$v.html|html_entity_decode}|-{$v.name}</option>
										{/foreach}
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td><label for="">商品品牌</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="brand_id">
										<option value="0">请选择商品品牌</option>
										{foreach name="brands" item="v"}
										<option value="{$v.id}"{if condition="$info['brand_id'] eq $v['id']"} selected{/if}>{$v.name}</option>
										{/foreach}
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td><label for="">所属商户</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="store_id">
										<option value="0">请选择所属商户</option>
										{foreach name="stores" item="v"}
										<option value="{$v.id}"{if condition="$info['store_id'] eq $v['id']"} selected{/if}>{$v.name}</option>
										{/foreach}
									</select>
								</div>
							</td>
						</tr>
						<tr  style="display: none">
							<td><label for="">供应商</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="supplier_id">
										<option value="0">请选择供应商</option>
										{foreach name="suppliers" item="v"}
										<option value="{$v.id}"{if condition="$info['supplier_id'] eq $v['id']"} selected{/if}>{$v.name}</option>
										{/foreach}
									</select>
								</div>
							</td>
						</tr>

						<tr  style="display: none">
							<td><label for="goods_type">商品品类</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="goods_type">
										<option value="1"{if condition="$info['goods_type'] eq 1"} selected{/if}>实物</option>
										<option value="2"{if condition="$info['goods_type'] eq 2"} selected{/if}>虚拟产品</option>
									</select>
								</div>
							</td>
						</tr>

						<tr  style="display: none">
							<td><label for="type">商品类型</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="type">
										<option value="1"{if condition="$info['type'] eq 1"} selected{/if}>商城商品</option>
										<option value="2"{if condition="$info['type'] eq 2"} selected{/if}>积分商品</option>
									</select>
								</div>
							</td>
						</tr>



						<tr>
							<td width="15%"><label for="goods_unit">商品单位</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="goods_unit" id="goods_unit" placeholder="请输入商品单位" value="{$info.goods_unit|default=''}" /></td>
						</tr>
						<tr>
							<td width="15%"><label for="cost_price">成本价</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="cost_price" id="cost_price" placeholder="请输入成本价" value="{$info.cost_price|default='0.00'}"{if condition="$info && $info['goods_spec_format']"} readonly{/if} /><span>元</span></td>
						</tr>
						<tr>
							<td width="15%"><label for="market_price">市场价</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="market_price" id="market_price" placeholder="请输入市场价" value="{$info.market_price|default='0.00'}"{if condition="$info && $info['goods_spec_format']"} readonly{/if} /><span>元</span></td>
						</tr>
						<tr>
							<td width="15%"><label for="sale_price">销售价<em>*</em></label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="sale_price" id="sale_price" placeholder="请输入销售价" value="{$info.sale_price|default='0.00'}"{if condition="$info && $info['goods_spec_format']"} readonly{/if} /><span>元</span></td>
						</tr>
						<tr  style="display: none">
							<td width="15%"><label for="give_points">赠送积分<em>*</em></label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="give_points" id="give_points" placeholder="请输入赠送的积分" value="{$info.give_points|default='0'}"{if condition="$info && $info['goods_spec_format']"} readonly{/if} /><span>积分，请填写具体赠送积分的数值，0 或不填则按照系统设置 》积分设置中的比例计算。</span></td>
						</tr>
						<tr >
							<td width="15%"><label for="diy_sale_nums">自定义销量</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="diy_sale_nums" id="diy_sale_nums" placeholder="请输入自定义销量" value="{$info.diy_sale_nums|default='0'}" /></td>
						</tr>
						<tr  style="display: none">
							<td width="15%"><label for="actual_sale_nums">实际销量</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="actual_sale_nums" id="actual_sale_nums" placeholder="请输入实际销量" value="{$info.actual_sale_nums|default='0'}" readonly /></td>
						</tr>
						<tr>
							<td width="15%"><label for="goods_stock">总库存<em>*</em></label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="goods_stock" id="goods_stock" placeholder="请输入总库存" value="{$info.goods_stock|default='0'}"{if condition="$info && $info['goods_spec_format']"} readonly{/if} /></td>
						</tr>
						<tr  style="display: none">
							<td width="15%"><label for="goods_stock_alarm">库存预警</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="goods_stock_alarm" id="goods_stock_alarm" placeholder="请输入库存预警数量" value="{$info.goods_stock_alarm|default='0'}" /><span>设置最低库存预警值。当库存低于预警值时商家中心商品列表页库存列红字提醒。0 为不预警。</span></td>
						</tr>
						<tr>
							<th colspan="2">商品模型</th>
						</tr>
						<tr>
							<td rowspan="2"><label for="">商品模型</label></td>
							<td>
								<div class="lay-select m-select-def">
									<select name="good_mods_id" lay-filter="good_mods_id">
										<option value="0">请选择商品模型</option>
										{foreach name="goodMods" item="v"}
										<option value="{$v.id}"{if condition="$info['good_mods_id'] eq $v['id']"} selected{/if}>{$v.name}</option>
										{/foreach}
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td class="m-good-specs">
								<table class="m-table">
									<thead>
									<tr>
										<th colspan="2">
											<h3>操作提示</h3>
											<p>1、双击规格值进行编辑操作（失去光标自动保存）。</p>
											<p>2、鼠标浮上图片时，可以进行预览。</p>
										</th>
									</tr>
									</thead>
									<tbody id="j_spec"></tbody>
								</table>
							</td>
						</tr>
						<tr id="j_sku" class="dn">
							<td><label for="">商品sku</label></td>
							<td class="m-good-sku" id="j_good_sku"></td>
						</tr>
						<tr id="j_attr" class="dn">
							<td><label for="">商品属性</label></td>
							<td class="m-good-attrs">
								<table class="m-table">
									<tbody id="j_good_attr"></tbody>
								</table>
							</td>
						</tr>
						<tr>
							<th colspan="2">商品图片</th>
						</tr>
						<tr>
							<td><label for="">商品缩略图</label></td>
							<td>
								<button type="button" class="layui-btn u-upload-pic" data-name="goods_thumb_id"><i class="layui-icon">&#xe67c;</i>上传图片</button>
								<div class="m-pic">
									<ul>
										{:attach_html($info.goods_thumb_id, 'goods_thumb_id')}
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<td><label for="">商品相册</label></td>
							<td>
								<button type="button" class="layui-btn u-upload-pics" data-name="goods_album"><i class="layui-icon">&#xe67c;</i>上传图片</button>
								<div class="m-pics">
									<ul>
										{:attach_html($info.goods_album, 'goods_album', 'pics')}
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<td><label for="">商品详情相册</label></td>
							<td>
								<button type="button" class="layui-btn u-upload-pics" data-name="goods_album_content"><i class="layui-icon">&#xe67c;</i>上传图片</button>
								<div class="m-pics">
									<ul>
										{:attach_html($info.goods_album_content, 'goods_album_content', 'pics')}
									</ul>
								</div>
							</td>
						</tr>
						<tr  style="display: none">
							<td><label for="goods_video">商品视频</label></td>
							<td>
								<button type="button" class="layui-btn u-upload-file" data-name="goods_video"><i class="layui-icon">&#xe67c;</i>上传视频</button>
								<div class="m-files">
									<ul class="m-jquery-sorted">
										{:attach_html($info.goods_video, 'goods_video', 'file')}
									</ul>
								</div>
							</td>
						</tr>
						<tr  style="display: none">
							<td><label for="goods_keywords">商品关键词</label></td>
							<td><input type="text" class="u-ipt u-ipt-long" name="goods_keywords" id="goods_keywords" placeholder="请输入商品关键词" value="{$info.goods_keywords}" /></td>
						</tr>
						<tr>
							<td><label for="goods_intro">商品简介</label></td>
							<td><div class="m-textarea"><textarea name="goods_intro" class="u-tarea" id="goods_intro" placeholder="请输入商品简介">{$info.goods_intro}</textarea></div></td>
						</tr>
						<tr>
							<th colspan="2">商品详情</th>
						</tr>
						<tr>
							<td colspan="2"><label for="">产品参数<em>*</em></label></td>
						</tr>
						<tr  id="a_table">
							<td><a href="javascript:;" title="添加项目" class="u-plus" id="a"><i class="icon-plus"></i></a></td>
							{volist name='$info.parameter_list' id='v'}
							<tr>
								<td><input type="text" name="parameter[$key][name]" value="{$v.name}"></td>
								<td><input type="text" name="parameter[$key][value]" value="{$v.value}"></td>
							</tr>
							{/volist}
						</tr>

						<tr>
							<td colspan="2"><label for="">商品详情<em>*</em></label></td>
						</tr>
						<tr>
							<td colspan="2"><textarea name="goods_detail" style="width:100%;height:300px;visibility:hidden;">{$info.goods_detail}</textarea></td>
						</tr>
						<tr>
							<th colspan="2">其他信息</th>
						</tr>
						<tr>
							<td><label for="">是否上架</label></td>
							<td><div class="lay-checked"><input type="checkbox" name="is_sale" value="1" title="是" lay-skin="primary"{$info.is_sale ? ' checked' : ''} /></div></td>
						</tr>
						<tr style="display: none">
							<td><label for="">是否新品</label></td>
							<td><div class="lay-checked"><input type="checkbox" name="is_latest" value="1" title="是" lay-skin="primary"{$info.is_latest ? ' checked' : ''} /></div></td>
						</tr>
						<tr  style="display: none">
							<td><label for="">是否热卖</label></td>
							<td><div class="lay-checked"><input type="checkbox" name="is_hot_sale" value="1" title="是" lay-skin="primary"{$info.is_hot_sale ? ' checked' : ''} /></div></td>
						</tr>
						<tr>
							<td><label for="">是否推荐</label></td>
							<td><div class="lay-checked"><input type="checkbox" name="is_recommand" value="1" title="是" lay-skin="primary"{$info.is_recommand ? ' checked' : ''} /></div></td>
						</tr>
						<tr style="display: none">
							<td><label for="">页面是否显示库存</label></td>
							<td><div class="lay-checked"><input type="checkbox" name="is_stock_visible" value="1" title="是" lay-skin="primary"{$info.is_stock_visible ? ' checked' : ''} /></div></td>
						</tr>
						<tr style="display: none">
							<td width="15%"><label for="max_purchase_nums">每人限购</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="max_purchase_nums" id="max_purchase_nums" placeholder="请输入每人限购数量" value="{$info.max_purchase_nums|default='0'}" /><span>0 为不限制</span></td>
						</tr>
						<tr style="display: none">
							<td width="15%"><label for="min_purchase_nums">最少购买数量</label></td>
							<td><input type="text" class="u-ipt u-ipt-small" name="min_purchase_nums" id="min_purchase_nums" placeholder="请输入最少购买数量" value="{$info.min_purchase_nums|default='0'}" /><span>0 为不限制</span></td>
						</tr>
						<tr style="display: none">
							<td><label for="list_order">排序</label></td>
							<td><input type="text" class="u-ipt u-ipt-tiny" name="list_order" id="list_order" placeholder="请输入排序值" value="{$info.list_order|default=0}" /><span>值越大越排在前面</span></td>
						</tr>
						</tbody>
					</table>
					<div class="m-form-btn">
						<input type="hidden" name="id" value="{$info.id}"><button id="j_add_goods" class="u-btn">确定提交</button></div>
					<textarea name="goods_spec_format" class="dn"></textarea>
				</form>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="extrajs"}
<script src="__STATIC__/public/js/jquery-ui.min.js"></script>
{include file="public:upload"/}
{include file="public:editor"/}
<script>
    var good_mods_id      = '{$info.good_mods_id}';
    var goods_spec_format = eval('{$info.goods_spec_format ? html_entity_decode($info.goods_spec_format) : "[]"}');
    var goods_sku         = eval('{$sku ? html_entity_decode($sku) : "[]"}');
    var goods_attr        = eval('{$attr ? html_entity_decode($attr) : "[]"}');
    var upload_uri        = '{:url("api/v1/upload", ["path" => session("userid", "", session_prefix()), "type" => "image", "module" => request()->module() ?: "addons"])}';
    var upload_btn        = '__STATIC__/manage/images/goods_sku_add.png';
    var uri               = $('input[name="action_uri"]').val();
    KindEditor.ready(function(K) {
        var editor = K.create('textarea[name="goods_detail"]', {
            allowFileManager: true,
            uploadJson: uploadJson,
            fileManagerJson: fileManagerJson,
            afterBlur: function () {
                this.sync();
            }
        });
    });
</script><script>
    /**
     * 参数添加
     */
    var kindex = 0
    $("#a").click(function(){
        kindex++
        var form_html="";
        form_html+="<tr>";
        form_html+="<td><input type=\"text\" name=\"parameter["+kindex+"][name]\" value=\"\"></td>";
        form_html+="<td><input type=\"text\" name=\"parameter["+kindex+"][value]\" value=\"\" style='width:60px;'></td>";
        form_html+="<td><a href=\"javascript:;\" title=\"删除\" class=\"u-inside-del\" data-id=\""+kindex+"\"><i class=\"icon-trash\"></i></a></td>";
        form_html+="</tr>";
        $("#a_table").append(form_html);
    });

    /**
     * 参数删除
     */
    $("#a_table").on("click",".u-inside-del",function(){
        var id=$(this).attr("data-id");
        var obj=$(this);
        console.log(id)
        if(id == kindex){
            kindex--
        }

        obj.parent().parent().remove();
    });
</script>
<script src="__STATIC__/public/js/good_add.js"></script>
{/block}
